package com.cily.utils.t_webrtc.singlr;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import com.cily.utils.t_webrtc.BaseAc3;
import com.cily.utils.t_webrtc.R;
import com.cily.utils.t_webrtc.singlr.Services.SignalRService;


public class MainPadActivity extends BaseAc3 {
    public final Context mContext = this;
    public SignalRService mService;
    public boolean mBound = false;
    /**
     * Defines callbacks for service binding, passed to bindService()
     */
    private final ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            // We've bound to SignalRService, cast the IBinder and get SignalRService instance
            SignalRService.LocalBinder binder = (SignalRService.LocalBinder) service;
            mService = binder.getService();
            mBound = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName arg0) {
            mBound = false;
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_pad);


        Intent intent = new Intent(MainPadActivity.this, SignalRService.class);
        bindService(intent, mConnection, BIND_AUTO_CREATE);
//        Intent i = new Intent(this, SignalRService.class);
//        startService(i);

//        Intent index = new Intent(this, IndexActivity.class);
//        startActivity(index);
    }

    public void sendMessage(String jsonMessage) {
        if (mBound) {
            mService.sendMessage(jsonMessage);
        }
    }

}
